const app = getApp();

Page({

  data: {
    showPage:false,
    showQRCodePopup:false,
    dataType: 'all', // 列表类型
  },
  onLoad(options) {
    let t = this,token = wx.getStorageSync('ACCESS_TOKEN')
      if(token){
        t.setData({token:token})
        wx.showLoading({title: '加载中',mask:true})
        t.getOrderList(token)
        wx.hideLoading({
          complete:function(){t.setData({showPage:true})}
        })
      }else {
        app.args.page.onLoad(this, e)
      }
  },
  getOrderList(token) {
    let _this = this;
    app.args.request({
      url: app.args.api.siteinfo.sitelive + 'integral/exchangeRecord',
      data:{
          storeId: app.args.api.siteinfo.hosId2,
          openId:'oSdH80GceCJqgJ-RVAIo_ETdQeoU'
      },
      success(res){
        console.log(res)
        res.code == 0 && _this.setData({list: res.data})
      }
    })
  },
  bindHeaderTap(e) {
    let t = this, type = e.currentTarget.dataset.type
    t.getOrderList()
  },
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 88), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      scrollHeight
    });
  },

  /**
   * 查看核销二维码
   */
  onExtractQRCode(e) {
    let _this = this,order_id = e.currentTarget.dataset.id
    wx.showLoading({title: '加载中',mask:true})
    app.args.request({
      url: app.args.api.siteinfo.sitelive + 'integral/jfqrcode',
      data:{
          storeId: app.args.api.siteinfo.hosId2,
          openId:_this.data.token,
          recordId:order_id
      },
      success(res){
        console.log(res)
        _this.setData({QRCodeImage: res.codeimg})
        wx.hideLoading()
        _this.onToggleQRCodePopup();
      }
    })
  },

  /**
   * 核销码弹出层
   */
  onToggleQRCodePopup() {
    let _this = this;
    _this.setData({
      showQRCodePopup: !_this.data.showQRCodePopup
    });
  },

});